package org.parklab.lab.web.client.data.chat;

import java.io.Serializable;
import java.util.HashMap;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.parklab.lab.web.client.data.user.UserInfo;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class ChatInfo implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6847092391289969265L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String chatKey;

	@Persistent
	private HashMap<String, UserInfo> userList = new HashMap<String, UserInfo>();
	
	public ChatInfo() {
	} // for Serializable

	public ChatInfo(String chatKey, UserInfo creator) {
		this.chatKey = chatKey;
		this.addUser(creator);
	}

	public Long getId() {
		return id;
	}

	/**
	 * @return the chatKey
	 */
	public String getChatKey() {
		return chatKey;
	}

	/**
	 * @param chatKey the chatKey to set
	 */
	public void setChatKey(String chatKey) {
		this.chatKey = chatKey;
	}

	public UserInfo[] getUsers() {
		return userList.values().toArray(new UserInfo[0]);
	}
	
	public void addUser(UserInfo userInfo) {
		userList.put(userInfo.getUserId(), userInfo);
	}
	
	public void delUser(String userKey) {
		userList.remove(userKey);
	}
	
}